package StudyCode.summary.csv;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class EncodesCSVAcceptableValue {
	private static final String ENCLOSURE = "\"";
	private static final String EMPTY = "";

	public static void main(String[] args) {
		String str = "www.tah1986.com\"\"";
		System.out.println("编码前: " + str);
		System.out.println("编码后: " + csvEncode(str));
	}

	public static String csvEncode(int value) {
		return csvEncode(String.valueOf(value));
	}


	public static String csvEncode(String value) {
		if (value == null) {
			value = EMPTY;
		} else {
			value = value.replaceAll(ENCLOSURE, ENCLOSURE + ENCLOSURE);
			value = ENCLOSURE + value + ENCLOSURE;
		}

		return value;
	}


	public static String csvEncode(Object value) {
		return value != null ? csvEncode(String.valueOf(value)) : EMPTY;
	}
}
